package com.zh.file.service.impl;

import com.zh.file.entity.SysAttachment;
import com.zh.file.mapper.SysAttachmentMapper;
import com.zh.file.service.HelloService;
import com.zh.file.service.TestTransactional2Service;
import com.zh.file.service.UploadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Description:
 * @ClassName HelloServiceImpl
 * @date: 2020.12.10 19:55
 * @Author: zhanghang
 */
@Service("helloService1")
public class HelloServiceImpl implements HelloService {
    @Autowired
    private SysAttachmentMapper sysAttachmentMapper;

    @Autowired
    private UploadFileService uploadFileService1;

    @Autowired
    private TestTransactional2Service testTransactional2Service;
    @Override
//    @Transactional
    public String hello() {
        SysAttachment sysAttachment = new SysAttachment();
        sysAttachment.setAppendixId("ert");
        sysAttachment.setFileType("ert");
        sysAttachment.setFileTypeCode("ert");
        sysAttachment.setTaskId(1L);
        sysAttachment.setTaskName("ert");
        sysAttachment.setTaskNameCode("ert");

        int insert = sysAttachmentMapper.insert(sysAttachment);
        testTransactional2Service.testAdd();
//        if (1/1 == 1){
//            throw new RuntimeException("自定义一场");
//        }
//        System.out.println("返回数据"+uploadFileService1.add(sysAttachment.getId()));
        return insert > 0 ? "添加成功" : "添加失败";
    }

    @Async("threadPoolTask")
    @Override
    public void msg() {
        System.out.println(Thread.currentThread().getName()+"===start===");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"===end===");

    }
}
